import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase = 'DBshop009_销售管理退货管理搜索流程'

# 前端用户进行退货
# 实例化并打开网页
firefox = openBrowser(url)
# 登录
DBshopLogin(firefox, userName, password)
firefox.find_element_by_link_text('我的订单').click()
firefox.find_element_by_link_text('退货申请').click()
firefox.find_element_by_link_text('点此申请退货').click()
rootPath = get_pro_rootpath() # 获取项目的绝对路径
filePath = rootPath+r'\public\order1.txt' # 拼接文件路径
orderNo = readFile(filePath) # 读取文件中的订单编号
firefox.find_element_by_id('order_sn').send_keys(orderNo)
time.sleep(1)
firefox.find_element_by_id('search-order').click()
time.sleep(1)
firefox.find_element_by_id('refund_info').send_keys('退货')
firefox.find_element_by_xpath('//button[text()="申请退货"]').click()
time.sleep(1)
firefox.switch_to.alert.accept()
time.sleep(1)

firefox = openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)
# 1.点击商品管理退货管理。
DBshopEnterMenu2(firefox, '销售管理', '退货管理')
# 2.点击退货方式，选择框选择“退货到账户余额”点击“搜索”按钮。
firefox.find_element_by_xpath('//select[@name="refund_type"]/option[2]').click()
firefox.find_element_by_xpath('//button[contains(.,"搜索")]').click()

# 断言
try:
    if firefox.find_element_by_xpath('//td[text()="%s"]/following-sibling::td[2]' % orderNo).text == '退款到账户余额':
        writeLog("%s 测试通过" % testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
    firefox.quit()